package com.gidgabs.modules.api.service.discovery;

import com.gidgabs.common.utils.Assist;
import com.gidgabs.common.utils.LangUtil;
import com.gidgabs.common.utils.ReturnJson;
import com.gidgabs.dto.TbUserJournalDto;
import com.gidgabs.modules.dao.TbAliyunVideoDao;
import com.gidgabs.modules.dao.TbUserJournalDao;
import com.gidgabs.modules.entity.TbAliyunVideoEntity;
import com.gidgabs.modules.entity.TbUserJournalEntity;
import com.gidgabs.utils.SessionDataUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by tby on 2018/7/10.
 */
@Service
@Transactional
public class DiscoveryJournalService {
    @Autowired private TbUserJournalDao tbUserJournalDao;
    @Autowired private TbAliyunVideoDao tbAliyunVideoDao;


    /**
     * 查询用户发表的日志
     * @param pageSize
     * @param pageNo
     * @param uerId
     * @return
     */
    public ReturnJson<TbUserJournalDto> queryList(Integer pageSize, Integer pageNo, Integer uerId) {
        Assist assist=new Assist();
        assist.andEq("delete_type",0).andEq("userId", uerId)
                .andEq("status",1)
                .setOrder(Assist.order("create_time",false))
                .setRowSize(pageSize)
                .setStartRow(LangUtil.firstLimit(pageSize,pageNo));
        List<TbUserJournalEntity> journalEntities = tbUserJournalDao.selectTbUserJournal(assist);

        List<TbUserJournalDto> tbUserJournalDtos=new ArrayList<>();
        for (TbUserJournalEntity tbUserJournalEntity:journalEntities){
            TbAliyunVideoEntity aliyunVideoEntity = tbAliyunVideoDao.queryObject(tbUserJournalEntity.getGidgabsVideoId());
            tbUserJournalDtos.add(tbUserJournalEntity.toDto(aliyunVideoEntity));
        }
        return ReturnJson.success("查询成功",tbUserJournalDtos);
    }
}
